<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="Python批量处理Word文件, ZJZ&#39;s Blogs">
    <meta name="description" content=" 部分功能尚需完善，敬请期待．．．
先上图：
界面UI(doc2docx.ui)代码：  &amp;lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt;
&amp;lt;ui version=&#34;4.0&#34;&gt;
 &amp;lt;class&gt;">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="referrer" content="no-referrer-when-downgrade">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>Python批量处理Word文件 | ZJZ&#39;s Blogs</title>
    <link rel="icon" type="image/png" href="/programming/favicon.png">
    


    <!-- bg-cover style     -->



<link rel="stylesheet" type="text/css" href="/programming/libs/awesome/css/all.min.css">
<link rel="stylesheet" type="text/css" href="/programming/libs/materialize/materialize.min.css">
<link rel="stylesheet" type="text/css" href="/programming/libs/aos/aos.css">
<link rel="stylesheet" type="text/css" href="/programming/libs/animate/animate.min.css">
<link rel="stylesheet" type="text/css" href="/programming/libs/lightGallery/css/lightgallery.min.css">
<link rel="stylesheet" type="text/css" href="/programming/css/matery.css">
<link rel="stylesheet" type="text/css" href="/programming/css/my.css">
<link rel="stylesheet" type="text/css" href="/programming/css/dark.css" media="none" onload="if(media!='all')media='all'">




    <link rel="stylesheet" href="/programming/libs/tocbot/tocbot.css">
    <link rel="stylesheet" href="/programming/css/post.css">




    
        <link rel="stylesheet" type="text/css" href="/programming/css/reward.css">
    



    <script src="/programming/libs/jquery/jquery-3.6.0.min.js"></script>

<meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/programming/atom.xml" title="ZJZ's Blogs" type="application/atom+xml">
</head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/programming/" class="waves-effect waves-light">
                    
                    <img src="/programming/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">ZJZ&#39;s Blogs</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/programming/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/programming/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/programming/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/programming/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/programming/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/programming/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/programming/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
  <li>
    <a href="javascript:;" class="waves-effect waves-light" onclick="switchNightMode()" title="深色/浅色模式" >
      <i id="sum-moon-icon" class="fas fa-sun" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/programming/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">ZJZ&#39;s Blogs</div>
        <div class="logo-desc">
            
            Never really desperate, only the lost of the soul.
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/programming/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/programming/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/programming/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/programming/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/programming/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/programming/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/programming/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/blinkfox/hexo-theme-matery" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/blinkfox/hexo-theme-matery" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/programming/medias/featureimages/3.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">Python批量处理Word文件</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/programming/tags/word/">
                                <span class="chip bg-color">word</span>
                            </a>
                        
                            <a href="/programming/tags/python/">
                                <span class="chip bg-color">python</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/programming/categories/%E7%BC%96%E7%A8%8B/" class="post-category">
                                编程
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2024-01-19
                </div>
                

                

                

                

                
            </div>
        </div>
        <hr class="clearfix">

        
        <!-- 是否加载使用自带的 prismjs. -->
        <link rel="stylesheet" href="/programming/libs/prism/prism.min.css">
        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <p> 部分功能尚需完善，敬请期待．．．</p>
<h2 id="先上图："><a href="#先上图：" class="headerlink" title="先上图："></a>先上图：</h2><p><img src="/programming/images/Python%E6%89%B9%E9%87%8F%E5%A4%84%E7%90%86Word%E6%96%87%E4%BB%B6.png" alt="Word文档批量操作1"></p>
<h2 id="界面UI-doc2docx-ui-代码："><a href="#界面UI-doc2docx-ui-代码：" class="headerlink" title="界面UI(doc2docx.ui)代码："></a>界面UI(doc2docx.ui)代码：</h2> <pre class="line-numbers language-python" data-language="python"><code class="language-python"> <span class="token operator">&lt;</span>?xml version<span class="token operator">=</span><span class="token string">"1.0"</span> encoding<span class="token operator">=</span><span class="token string">"UTF-8"</span>?<span class="token operator">></span>
<span class="token operator">&lt;</span>ui version<span class="token operator">=</span><span class="token string">"4.0"</span><span class="token operator">></span>
 <span class="token operator">&lt;</span><span class="token keyword">class</span><span class="token operator">></span>MainWindow<span class="token operator">&lt;</span><span class="token operator">/</span><span class="token keyword">class</span><span class="token operator">></span>
 <span class="token operator">&lt;</span>widget <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">"QMainWindow"</span> name<span class="token operator">=</span><span class="token string">"MainWindow"</span><span class="token operator">></span>
  <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"geometry"</span><span class="token operator">></span>
   <span class="token operator">&lt;</span>rect<span class="token operator">></span>
    <span class="token operator">&lt;</span>x<span class="token operator">></span><span class="token number">0</span><span class="token operator">&lt;</span><span class="token operator">/</span>x<span class="token operator">></span>
    <span class="token operator">&lt;</span>y<span class="token operator">></span><span class="token number">0</span><span class="token operator">&lt;</span><span class="token operator">/</span>y<span class="token operator">></span>
    <span class="token operator">&lt;</span>width<span class="token operator">></span><span class="token number">500</span><span class="token operator">&lt;</span><span class="token operator">/</span>width<span class="token operator">></span>
    <span class="token operator">&lt;</span>height<span class="token operator">></span><span class="token number">430</span><span class="token operator">&lt;</span><span class="token operator">/</span>height<span class="token operator">></span>
   <span class="token operator">&lt;</span><span class="token operator">/</span>rect<span class="token operator">></span>
  <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
  <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"minimumSize"</span><span class="token operator">></span>
   <span class="token operator">&lt;</span>size<span class="token operator">></span>
    <span class="token operator">&lt;</span>width<span class="token operator">></span><span class="token number">500</span><span class="token operator">&lt;</span><span class="token operator">/</span>width<span class="token operator">></span>
    <span class="token operator">&lt;</span>height<span class="token operator">></span><span class="token number">430</span><span class="token operator">&lt;</span><span class="token operator">/</span>height<span class="token operator">></span>
   <span class="token operator">&lt;</span><span class="token operator">/</span>size<span class="token operator">></span>
  <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
  <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"maximumSize"</span><span class="token operator">></span>
   <span class="token operator">&lt;</span>size<span class="token operator">></span>
    <span class="token operator">&lt;</span>width<span class="token operator">></span><span class="token number">500</span><span class="token operator">&lt;</span><span class="token operator">/</span>width<span class="token operator">></span>
    <span class="token operator">&lt;</span>height<span class="token operator">></span><span class="token number">430</span><span class="token operator">&lt;</span><span class="token operator">/</span>height<span class="token operator">></span>
   <span class="token operator">&lt;</span><span class="token operator">/</span>size<span class="token operator">></span>
  <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
  <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"windowTitle"</span><span class="token operator">></span>
   <span class="token operator">&lt;</span>string<span class="token operator">></span>doc2docx<span class="token operator">&lt;</span><span class="token operator">/</span>string<span class="token operator">></span>
  <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
  <span class="token operator">&lt;</span>widget <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">"QWidget"</span> name<span class="token operator">=</span><span class="token string">"centralwidget"</span><span class="token operator">></span>
   <span class="token operator">&lt;</span>widget <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">"QLineEdit"</span> name<span class="token operator">=</span><span class="token string">"docLineEdit"</span><span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"geometry"</span><span class="token operator">></span>
     <span class="token operator">&lt;</span>rect<span class="token operator">></span>
      <span class="token operator">&lt;</span>x<span class="token operator">></span><span class="token number">60</span><span class="token operator">&lt;</span><span class="token operator">/</span>x<span class="token operator">></span>
      <span class="token operator">&lt;</span>y<span class="token operator">></span><span class="token number">40</span><span class="token operator">&lt;</span><span class="token operator">/</span>y<span class="token operator">></span>
      <span class="token operator">&lt;</span>width<span class="token operator">></span><span class="token number">260</span><span class="token operator">&lt;</span><span class="token operator">/</span>width<span class="token operator">></span>
      <span class="token operator">&lt;</span>height<span class="token operator">></span><span class="token number">20</span><span class="token operator">&lt;</span><span class="token operator">/</span>height<span class="token operator">></span>
     <span class="token operator">&lt;</span><span class="token operator">/</span>rect<span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
   <span class="token operator">&lt;</span><span class="token operator">/</span>widget<span class="token operator">></span>
   <span class="token operator">&lt;</span>widget <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">"QPushButton"</span> name<span class="token operator">=</span><span class="token string">"docBtn"</span><span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"geometry"</span><span class="token operator">></span>
     <span class="token operator">&lt;</span>rect<span class="token operator">></span>
      <span class="token operator">&lt;</span>x<span class="token operator">></span><span class="token number">340</span><span class="token operator">&lt;</span><span class="token operator">/</span>x<span class="token operator">></span>
      <span class="token operator">&lt;</span>y<span class="token operator">></span><span class="token number">40</span><span class="token operator">&lt;</span><span class="token operator">/</span>y<span class="token operator">></span>
      <span class="token operator">&lt;</span>width<span class="token operator">></span><span class="token number">100</span><span class="token operator">&lt;</span><span class="token operator">/</span>width<span class="token operator">></span>
      <span class="token operator">&lt;</span>height<span class="token operator">></span><span class="token number">23</span><span class="token operator">&lt;</span><span class="token operator">/</span>height<span class="token operator">></span>
     <span class="token operator">&lt;</span><span class="token operator">/</span>rect<span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"text"</span><span class="token operator">></span>
     <span class="token operator">&lt;</span>string<span class="token operator">></span>选择输入文件夹<span class="token operator">&lt;</span><span class="token operator">/</span>string<span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
   <span class="token operator">&lt;</span><span class="token operator">/</span>widget<span class="token operator">></span>
   <span class="token operator">&lt;</span>widget <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">"QProgressBar"</span> name<span class="token operator">=</span><span class="token string">"progressBar"</span><span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"geometry"</span><span class="token operator">></span>
     <span class="token operator">&lt;</span>rect<span class="token operator">></span>
      <span class="token operator">&lt;</span>x<span class="token operator">></span><span class="token number">60</span><span class="token operator">&lt;</span><span class="token operator">/</span>x<span class="token operator">></span>
      <span class="token operator">&lt;</span>y<span class="token operator">></span><span class="token number">350</span><span class="token operator">&lt;</span><span class="token operator">/</span>y<span class="token operator">></span>
      <span class="token operator">&lt;</span>width<span class="token operator">></span><span class="token number">270</span><span class="token operator">&lt;</span><span class="token operator">/</span>width<span class="token operator">></span>
      <span class="token operator">&lt;</span>height<span class="token operator">></span><span class="token number">23</span><span class="token operator">&lt;</span><span class="token operator">/</span>height<span class="token operator">></span>
     <span class="token operator">&lt;</span><span class="token operator">/</span>rect<span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"value"</span><span class="token operator">></span>
     <span class="token operator">&lt;</span>number<span class="token operator">></span><span class="token number">24</span><span class="token operator">&lt;</span><span class="token operator">/</span>number<span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
   <span class="token operator">&lt;</span><span class="token operator">/</span>widget<span class="token operator">></span>
   <span class="token operator">&lt;</span>widget <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">"QPushButton"</span> name<span class="token operator">=</span><span class="token string">"docxBtn"</span><span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"geometry"</span><span class="token operator">></span>
     <span class="token operator">&lt;</span>rect<span class="token operator">></span>
      <span class="token operator">&lt;</span>x<span class="token operator">></span><span class="token number">340</span><span class="token operator">&lt;</span><span class="token operator">/</span>x<span class="token operator">></span>
      <span class="token operator">&lt;</span>y<span class="token operator">></span><span class="token number">80</span><span class="token operator">&lt;</span><span class="token operator">/</span>y<span class="token operator">></span>
      <span class="token operator">&lt;</span>width<span class="token operator">></span><span class="token number">100</span><span class="token operator">&lt;</span><span class="token operator">/</span>width<span class="token operator">></span>
      <span class="token operator">&lt;</span>height<span class="token operator">></span><span class="token number">23</span><span class="token operator">&lt;</span><span class="token operator">/</span>height<span class="token operator">></span>
     <span class="token operator">&lt;</span><span class="token operator">/</span>rect<span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"text"</span><span class="token operator">></span>
     <span class="token operator">&lt;</span>string<span class="token operator">></span>选择输出文件夹<span class="token operator">&lt;</span><span class="token operator">/</span>string<span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
   <span class="token operator">&lt;</span><span class="token operator">/</span>widget<span class="token operator">></span>
   <span class="token operator">&lt;</span>widget <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">"QLineEdit"</span> name<span class="token operator">=</span><span class="token string">"docxLineEdit"</span><span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"geometry"</span><span class="token operator">></span>
     <span class="token operator">&lt;</span>rect<span class="token operator">></span>
      <span class="token operator">&lt;</span>x<span class="token operator">></span><span class="token number">60</span><span class="token operator">&lt;</span><span class="token operator">/</span>x<span class="token operator">></span>
      <span class="token operator">&lt;</span>y<span class="token operator">></span><span class="token number">80</span><span class="token operator">&lt;</span><span class="token operator">/</span>y<span class="token operator">></span>
      <span class="token operator">&lt;</span>width<span class="token operator">></span><span class="token number">260</span><span class="token operator">&lt;</span><span class="token operator">/</span>width<span class="token operator">></span>
      <span class="token operator">&lt;</span>height<span class="token operator">></span><span class="token number">20</span><span class="token operator">&lt;</span><span class="token operator">/</span>height<span class="token operator">></span>
     <span class="token operator">&lt;</span><span class="token operator">/</span>rect<span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
   <span class="token operator">&lt;</span><span class="token operator">/</span>widget<span class="token operator">></span>
   <span class="token operator">&lt;</span>widget <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">"QTextEdit"</span> name<span class="token operator">=</span><span class="token string">"textEdit"</span><span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"geometry"</span><span class="token operator">></span>
     <span class="token operator">&lt;</span>rect<span class="token operator">></span>
      <span class="token operator">&lt;</span>x<span class="token operator">></span><span class="token number">60</span><span class="token operator">&lt;</span><span class="token operator">/</span>x<span class="token operator">></span>
      <span class="token operator">&lt;</span>y<span class="token operator">></span><span class="token number">140</span><span class="token operator">&lt;</span><span class="token operator">/</span>y<span class="token operator">></span>
      <span class="token operator">&lt;</span>width<span class="token operator">></span><span class="token number">380</span><span class="token operator">&lt;</span><span class="token operator">/</span>width<span class="token operator">></span>
      <span class="token operator">&lt;</span>height<span class="token operator">></span><span class="token number">190</span><span class="token operator">&lt;</span><span class="token operator">/</span>height<span class="token operator">></span>
     <span class="token operator">&lt;</span><span class="token operator">/</span>rect<span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
   <span class="token operator">&lt;</span><span class="token operator">/</span>widget<span class="token operator">></span>
   <span class="token operator">&lt;</span>widget <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">"QPushButton"</span> name<span class="token operator">=</span><span class="token string">"startBtn"</span><span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"geometry"</span><span class="token operator">></span>
     <span class="token operator">&lt;</span>rect<span class="token operator">></span>
      <span class="token operator">&lt;</span>x<span class="token operator">></span><span class="token number">340</span><span class="token operator">&lt;</span><span class="token operator">/</span>x<span class="token operator">></span>
      <span class="token operator">&lt;</span>y<span class="token operator">></span><span class="token number">350</span><span class="token operator">&lt;</span><span class="token operator">/</span>y<span class="token operator">></span>
      <span class="token operator">&lt;</span>width<span class="token operator">></span><span class="token number">100</span><span class="token operator">&lt;</span><span class="token operator">/</span>width<span class="token operator">></span>
      <span class="token operator">&lt;</span>height<span class="token operator">></span><span class="token number">23</span><span class="token operator">&lt;</span><span class="token operator">/</span>height<span class="token operator">></span>
     <span class="token operator">&lt;</span><span class="token operator">/</span>rect<span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"text"</span><span class="token operator">></span>
     <span class="token operator">&lt;</span>string<span class="token operator">></span>开始转换<span class="token operator">&lt;</span><span class="token operator">/</span>string<span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
   <span class="token operator">&lt;</span><span class="token operator">/</span>widget<span class="token operator">></span>
  <span class="token operator">&lt;</span><span class="token operator">/</span>widget<span class="token operator">></span>
  <span class="token operator">&lt;</span>widget <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">"QMenuBar"</span> name<span class="token operator">=</span><span class="token string">"menubar"</span><span class="token operator">></span>
   <span class="token operator">&lt;</span><span class="token builtin">property</span> name<span class="token operator">=</span><span class="token string">"geometry"</span><span class="token operator">></span>
    <span class="token operator">&lt;</span>rect<span class="token operator">></span>
     <span class="token operator">&lt;</span>x<span class="token operator">></span><span class="token number">0</span><span class="token operator">&lt;</span><span class="token operator">/</span>x<span class="token operator">></span>
     <span class="token operator">&lt;</span>y<span class="token operator">></span><span class="token number">0</span><span class="token operator">&lt;</span><span class="token operator">/</span>y<span class="token operator">></span>
     <span class="token operator">&lt;</span>width<span class="token operator">></span><span class="token number">500</span><span class="token operator">&lt;</span><span class="token operator">/</span>width<span class="token operator">></span>
     <span class="token operator">&lt;</span>height<span class="token operator">></span><span class="token number">23</span><span class="token operator">&lt;</span><span class="token operator">/</span>height<span class="token operator">></span>
    <span class="token operator">&lt;</span><span class="token operator">/</span>rect<span class="token operator">></span>
   <span class="token operator">&lt;</span><span class="token operator">/</span><span class="token builtin">property</span><span class="token operator">></span>
  <span class="token operator">&lt;</span><span class="token operator">/</span>widget<span class="token operator">></span>
  <span class="token operator">&lt;</span>widget <span class="token keyword">class</span><span class="token operator">=</span><span class="token string">"QStatusBar"</span> name<span class="token operator">=</span><span class="token string">"statusbar"</span><span class="token operator">/</span><span class="token operator">></span>
 <span class="token operator">&lt;</span><span class="token operator">/</span>widget<span class="token operator">></span>
 <span class="token operator">&lt;</span>resources<span class="token operator">/</span><span class="token operator">></span>
 <span class="token operator">&lt;</span>connections<span class="token operator">/</span><span class="token operator">></span>
<span class="token operator">&lt;</span><span class="token operator">/</span>ui<span class="token operator">></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<h2 id="主程序代码："><a href="#主程序代码：" class="headerlink" title="主程序代码："></a>主程序代码：</h2> <pre class="line-numbers language-python" data-language="python"><code class="language-python"> <span class="token comment"># -*- coding: utf-8 -*-</span>
<span class="token comment">#导入装换的包</span>
<span class="token keyword">import</span> win32com
<span class="token keyword">import</span> xlwt
<span class="token keyword">import</span> os
<span class="token keyword">import</span> re
<span class="token keyword">import</span> shutil
<span class="token keyword">from</span> win32com<span class="token punctuation">.</span>client <span class="token keyword">import</span> Dispatch<span class="token punctuation">,</span>constants

<span class="token comment">#导入界面的包</span>
<span class="token keyword">from</span> doc2docx <span class="token keyword">import</span> Ui_MainWindow
<span class="token keyword">import</span> sys
<span class="token keyword">import</span> doc2docx
<span class="token keyword">from</span> PyQt5<span class="token punctuation">.</span>QtWidgets <span class="token keyword">import</span> QApplication<span class="token punctuation">,</span> QMainWindow<span class="token punctuation">,</span> QFileDialog<span class="token punctuation">,</span> QMessageBox<span class="token punctuation">,</span> QAction
<span class="token keyword">import</span> docx
<span class="token keyword">from</span> docx<span class="token punctuation">.</span>shared <span class="token keyword">import</span> Cm<span class="token punctuation">,</span>Pt
<span class="token keyword">from</span> docx <span class="token keyword">import</span> Document
<span class="token keyword">from</span> docx<span class="token punctuation">.</span>enum<span class="token punctuation">.</span>text <span class="token keyword">import</span> WD_ALIGN_PARAGRAPH

<span class="token keyword">class</span> <span class="token class-name">SimpleDialogForm</span><span class="token punctuation">(</span>Ui_MainWindow<span class="token punctuation">,</span> QMainWindow<span class="token punctuation">)</span><span class="token punctuation">:</span>

    <span class="token comment"># 文件总数</span>
    totalList <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
    <span class="token comment"># 转换正确的文件总数</span>
    successList <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
    <span class="token comment"># 转换错误的文件总数</span>
    errorList <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>

    <span class="token keyword">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> parent <span class="token operator">=</span> <span class="token boolean">None</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token builtin">super</span><span class="token punctuation">(</span>SimpleDialogForm<span class="token punctuation">,</span> self<span class="token punctuation">)</span><span class="token punctuation">.</span>__init__<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>setupUi<span class="token punctuation">(</span>self<span class="token punctuation">)</span>  <span class="token comment"># 在此设置界面</span>

        <span class="token comment"># 父类的progressBar的值为24,这里设置为0</span>
        self<span class="token punctuation">.</span>progressBar<span class="token punctuation">.</span>setProperty<span class="token punctuation">(</span><span class="token string">"value"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>

        <span class="token comment">#兴建关于的条目</span>
        self<span class="token punctuation">.</span>about <span class="token operator">=</span> QAction<span class="token punctuation">(</span><span class="token string">"关于"</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>contact <span class="token operator">=</span> QAction<span class="token punctuation">(</span><span class="token string">"联系"</span><span class="token punctuation">)</span>
        <span class="token comment">#加上帮助菜单栏</span>
        helpMenu <span class="token operator">=</span> self<span class="token punctuation">.</span>menubar<span class="token punctuation">.</span>addMenu<span class="token punctuation">(</span><span class="token string">"帮助"</span><span class="token punctuation">)</span>
        <span class="token comment">#帮助菜单栏上加上条目</span>
        helpMenu<span class="token punctuation">.</span>addAction<span class="token punctuation">(</span>self<span class="token punctuation">.</span>about<span class="token punctuation">)</span>
        helpMenu<span class="token punctuation">.</span>addAction<span class="token punctuation">(</span>self<span class="token punctuation">.</span>contact<span class="token punctuation">)</span>

        <span class="token comment">#选中doc文件夹绑定的槽函数</span>
        self<span class="token punctuation">.</span>docBtn<span class="token punctuation">.</span>clicked<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>self<span class="token punctuation">.</span>setDocUrl<span class="token punctuation">)</span>
        <span class="token comment">#选中docx文件夹绑定的槽函数</span>
        self<span class="token punctuation">.</span>docxBtn<span class="token punctuation">.</span>clicked<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>self<span class="token punctuation">.</span>setDocxUrl<span class="token punctuation">)</span>
        <span class="token comment">#输入doc路径的输入框文本发生变化时绑定的槽</span>
        self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>textChanged<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>self<span class="token punctuation">.</span>initGUI<span class="token punctuation">)</span>
        <span class="token comment">#输入docx路径的输入框文本发生变化时绑定的槽</span>
        self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>textChanged<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>self<span class="token punctuation">.</span>initGUI<span class="token punctuation">)</span>
        <span class="token comment">#开始转换按钮绑定的槽函数</span>
        self<span class="token punctuation">.</span>startBtn1<span class="token punctuation">.</span>clicked<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>self<span class="token punctuation">.</span>renFilename<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>startBtn2<span class="token punctuation">.</span>clicked<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>self<span class="token punctuation">.</span>startConvertD<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>startBtn3<span class="token punctuation">.</span>clicked<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>self<span class="token punctuation">.</span>remove_H_F<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>startBtn4<span class="token punctuation">.</span>clicked<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>self<span class="token punctuation">.</span>addPageNumber<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>startBtn5<span class="token punctuation">.</span>clicked<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>self<span class="token punctuation">.</span>remove_H<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>startBtn6<span class="token punctuation">.</span>clicked<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>self<span class="token punctuation">.</span>startConvertP<span class="token punctuation">)</span>

        <span class="token comment">#显示关于窗口</span>
        self<span class="token punctuation">.</span>about<span class="token punctuation">.</span>triggered<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>self<span class="token punctuation">.</span>showAbout<span class="token punctuation">)</span>
        <span class="token comment">#显示联系作者窗口</span>
        self<span class="token punctuation">.</span>contact<span class="token punctuation">.</span>triggered<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>self<span class="token punctuation">.</span>contactAuthor<span class="token punctuation">)</span>

    <span class="token comment">#生成操作信息</span>
    <span class="token keyword">def</span> <span class="token function">writeMsg</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>

        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token string">"生成（操作信息.xlsx）"</span><span class="token punctuation">)</span>
        docUrl <span class="token operator">=</span> self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">if</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token string">''</span><span class="token punctuation">:</span>
            docxUrl<span class="token operator">=</span>docUrl
        <span class="token keyword">else</span><span class="token punctuation">:</span>
            docxUrl <span class="token operator">=</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        
        msgExcel <span class="token operator">=</span> docxUrl <span class="token operator">+</span> <span class="token string">'/操作信息.xlsx'</span>
        <span class="token keyword">print</span> <span class="token punctuation">(</span>msgExcel<span class="token punctuation">)</span>

        excel <span class="token operator">=</span> xlwt<span class="token punctuation">.</span>Workbook<span class="token punctuation">(</span>encoding<span class="token operator">=</span><span class="token string">'utf-8'</span><span class="token punctuation">)</span>
        <span class="token comment"># 这个是指定sheet页的名称</span>
        sheet1 <span class="token operator">=</span> excel<span class="token punctuation">.</span>add_sheet<span class="token punctuation">(</span><span class="token string">'统计信息'</span><span class="token punctuation">)</span>
        sheet2 <span class="token operator">=</span> excel<span class="token punctuation">.</span>add_sheet<span class="token punctuation">(</span><span class="token string">'详细信息'</span><span class="token punctuation">)</span>

        sheet1<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">'文件总数'</span><span class="token punctuation">)</span>
        sheet1<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'操作成功'</span><span class="token punctuation">)</span>
        sheet1<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">'操作失败'</span><span class="token punctuation">)</span>
        sheet1<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token builtin">len</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>totalList<span class="token punctuation">)</span><span class="token punctuation">)</span>
        sheet1<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token builtin">len</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>successList<span class="token punctuation">)</span><span class="token punctuation">)</span>
        sheet1<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token builtin">len</span><span class="token punctuation">(</span>self<span class="token punctuation">.</span>errorList<span class="token punctuation">)</span><span class="token punctuation">)</span>

        sheet2<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token string">'文件总数'</span><span class="token punctuation">)</span>
        sheet2<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">'操作成功'</span><span class="token punctuation">)</span>
        sheet2<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">'操作失败'</span><span class="token punctuation">)</span>

        row <span class="token operator">=</span> <span class="token number">1</span>
        <span class="token keyword">for</span> x <span class="token keyword">in</span> self<span class="token punctuation">.</span>totalList<span class="token punctuation">:</span>
            sheet2<span class="token punctuation">.</span>write<span class="token punctuation">(</span>row<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> x<span class="token punctuation">)</span>
            row <span class="token operator">+=</span> <span class="token number">1</span>

        row <span class="token operator">=</span> <span class="token number">1</span>
        <span class="token keyword">for</span> x <span class="token keyword">in</span> self<span class="token punctuation">.</span>successList<span class="token punctuation">:</span>
            sheet2<span class="token punctuation">.</span>write<span class="token punctuation">(</span>row<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> x<span class="token punctuation">)</span>
            row <span class="token operator">+=</span> <span class="token number">1</span>

        row <span class="token operator">=</span> <span class="token number">1</span>
        <span class="token keyword">for</span> x <span class="token keyword">in</span> self<span class="token punctuation">.</span>errorList<span class="token punctuation">:</span>
            sheet2<span class="token punctuation">.</span>write<span class="token punctuation">(</span>row<span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> x<span class="token punctuation">)</span>
            row <span class="token operator">+=</span> <span class="token number">1</span>

        excel<span class="token punctuation">.</span>save<span class="token punctuation">(</span>msgExcel<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>statusbar<span class="token punctuation">.</span>showMessage<span class="token punctuation">(</span><span class="token string">"操作完成，请到生成目录下打开(操作信息.xlsx)查看详细信息"</span><span class="token punctuation">,</span> <span class="token number">10000</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>setOp<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>

    <span class="token keyword">def</span> <span class="token function">setOp</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> flag<span class="token punctuation">)</span><span class="token punctuation">:</span>
        self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>setEnabled<span class="token punctuation">(</span>flag<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>setEnabled<span class="token punctuation">(</span>flag<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>docBtn<span class="token punctuation">.</span>setEnabled<span class="token punctuation">(</span>flag<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>docxBtn<span class="token punctuation">.</span>setEnabled<span class="token punctuation">(</span>flag<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>startBtn1<span class="token punctuation">.</span>setEnabled<span class="token punctuation">(</span>flag<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>startBtn2<span class="token punctuation">.</span>setEnabled<span class="token punctuation">(</span>flag<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>startBtn3<span class="token punctuation">.</span>setEnabled<span class="token punctuation">(</span>flag<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>startBtn4<span class="token punctuation">.</span>setEnabled<span class="token punctuation">(</span>flag<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>startBtn5<span class="token punctuation">.</span>setEnabled<span class="token punctuation">(</span>flag<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>startBtn6<span class="token punctuation">.</span>setEnabled<span class="token punctuation">(</span>flag<span class="token punctuation">)</span>

    <span class="token keyword">def</span> <span class="token function">setDocUrl</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token comment">#重新选择输入和输出目录时，进度条设置为0，文本框的内容置空</span>
        <span class="token builtin">str</span> <span class="token operator">=</span> QFileDialog<span class="token punctuation">.</span>getExistingDirectory<span class="token punctuation">(</span>self<span class="token punctuation">,</span><span class="token string">"选中源文件所在目录"</span><span class="token punctuation">,</span><span class="token string">r"E:\\"</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>setText<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>

    <span class="token keyword">def</span> <span class="token function">setDocxUrl</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token comment">#重新选择输入和输出目录时，进度条设置为0，文本框的内容置空</span>
        <span class="token builtin">str</span> <span class="token operator">=</span> QFileDialog<span class="token punctuation">.</span>getExistingDirectory<span class="token punctuation">(</span>self<span class="token punctuation">,</span><span class="token string">"选中新文件所在目录"</span><span class="token punctuation">,</span><span class="token string">r"E:\BaiduNetdiskWorkspace\test"</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>setText<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>

    <span class="token comment">#将图形界面的内容各种进度条，文本框初始化</span>
    <span class="token keyword">def</span> <span class="token function">initGUI</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        self<span class="token punctuation">.</span>progressBar<span class="token punctuation">.</span>setProperty<span class="token punctuation">(</span><span class="token string">"value"</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>setText<span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">)</span>

    <span class="token keyword">def</span> <span class="token function">initConfig</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token comment"># 文件总数</span>
        self<span class="token punctuation">.</span>totalList <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
        <span class="token comment"># 转换正确的文件总数</span>
        self<span class="token punctuation">.</span>successList <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
        <span class="token comment"># 装换错误的文件总数</span>
        self<span class="token punctuation">.</span>errorList <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>

    <span class="token comment">#处理文件名</span>
    <span class="token keyword">def</span> <span class="token function">renFilename</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token comment">#replaceStr[]</span>
        <span class="token comment"># 输入文件夹地址</span>
        path <span class="token operator">=</span> self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">if</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token string">''</span><span class="token punctuation">:</span>
            path2<span class="token operator">=</span>path
        <span class="token keyword">else</span><span class="token punctuation">:</span>
            path2 <span class="token operator">=</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>        
        files <span class="token operator">=</span> os<span class="token punctuation">.</span>listdir<span class="token punctuation">(</span>path<span class="token punctuation">)</span>
        pt <span class="token operator">=</span> <span class="token string">r'(\n)'</span>
        res <span class="token operator">=</span> re<span class="token punctuation">.</span>split<span class="token punctuation">(</span>pt<span class="token punctuation">,</span>self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>toPlainText<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">:</span><span class="token punctuation">]</span><span class="token comment">#读取textEdit中的内容，用第二行字符替换第一字符，第二行可为空</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"替换字符："</span><span class="token punctuation">,</span>res<span class="token punctuation">)</span>

        fileTotal <span class="token operator">=</span> <span class="token number">0</span>
        total <span class="token operator">=</span> <span class="token number">0</span>

        <span class="token keyword">for</span> <span class="token builtin">file</span> <span class="token keyword">in</span> files<span class="token punctuation">:</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">)</span><span class="token comment"># 输出所有文件名，只是为了看一下</span>
        fileTotal <span class="token operator">=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>files<span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"文件数："</span><span class="token punctuation">,</span>fileTotal<span class="token punctuation">)</span>

        <span class="token comment"># 获取旧名和新名</span>
        j<span class="token operator">=</span><span class="token number">0</span>
        <span class="token keyword">while</span> j <span class="token operator">&lt;</span> <span class="token builtin">len</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span><span class="token punctuation">:</span>
            total<span class="token operator">=</span><span class="token number">0</span>
            files <span class="token operator">=</span> os<span class="token punctuation">.</span>listdir<span class="token punctuation">(</span>path<span class="token punctuation">)</span>
            <span class="token keyword">for</span> <span class="token builtin">file</span> <span class="token keyword">in</span> files<span class="token punctuation">:</span>
                <span class="token comment"># old 旧名称的信息</span>
                old <span class="token operator">=</span> path <span class="token operator">+</span> os<span class="token punctuation">.</span>sep <span class="token operator">+</span> files<span class="token punctuation">[</span>total<span class="token punctuation">]</span>
                <span class="token comment">#print(total,"old:"+old)</span>
                <span class="token comment"># new是新名称的信息，这里的操作是用res[j]替换res[j+2]代表的字符，换行符也是一个字符串，故+2</span>
                new <span class="token operator">=</span> path2 <span class="token operator">+</span> os<span class="token punctuation">.</span>sep <span class="token operator">+</span> <span class="token builtin">file</span><span class="token punctuation">.</span>replace<span class="token punctuation">(</span>res<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">,</span>res<span class="token punctuation">[</span>j<span class="token operator">+</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
                <span class="token comment">#print(total,"new:"+new)</span>
                <span class="token keyword">if</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token string">''</span><span class="token punctuation">:</span>
                    os<span class="token punctuation">.</span>rename<span class="token punctuation">(</span>old<span class="token punctuation">,</span>new<span class="token punctuation">)</span> <span class="token comment"># 新旧替换</span>
                <span class="token keyword">else</span><span class="token punctuation">:</span>
                    shutil<span class="token punctuation">.</span>copyfile<span class="token punctuation">(</span>old<span class="token punctuation">,</span> new<span class="token punctuation">)</span>  <span class="token comment">#新文件路径非空时，复制并替换</span>
            
                self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span>files<span class="token punctuation">[</span>total<span class="token punctuation">]</span><span class="token punctuation">)</span>
                total<span class="token operator">+=</span><span class="token number">1</span>
                value <span class="token operator">=</span> total <span class="token operator">*</span> <span class="token number">1.0</span> <span class="token operator">/</span> fileTotal <span class="token operator">*</span> <span class="token number">100</span>
                self<span class="token punctuation">.</span>progressBar<span class="token punctuation">.</span>setValue<span class="token punctuation">(</span><span class="token builtin">int</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">)</span>
            j<span class="token operator">+=</span><span class="token number">4</span>
        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token string">"%d个文件名替换成功！"</span><span class="token operator">%</span>fileTotal<span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token string">"本次操作结束！"</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"%d个文件名替换成功！"</span><span class="token operator">%</span>fileTotal<span class="token punctuation">)</span>

    <span class="token comment">#转换为DOCX</span>
    <span class="token keyword">def</span> <span class="token function">startConvertD</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token keyword">if</span> self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token string">''</span> <span class="token punctuation">:</span><span class="token comment">#or self.docxLineEdit.text() == '':</span>
            msgBox <span class="token operator">=</span> QMessageBox<span class="token punctuation">(</span>QMessageBox<span class="token punctuation">.</span>Warning<span class="token punctuation">,</span> <span class="token string">"警告"</span><span class="token punctuation">,</span> <span class="token string">"请选中要转换的目录"</span><span class="token punctuation">)</span>
            msgBox<span class="token punctuation">.</span><span class="token keyword">exec</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span>
        self<span class="token punctuation">.</span>setOp<span class="token punctuation">(</span><span class="token boolean">False</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>initConfig<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token comment">#获取文本同时去掉空格</span>
        docUrl <span class="token operator">=</span> self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"原文件路径："</span> <span class="token operator">+</span> docUrl<span class="token punctuation">)</span>
        <span class="token keyword">if</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token string">''</span><span class="token punctuation">:</span>
            docxUrl<span class="token operator">=</span>docUrl
        <span class="token keyword">else</span><span class="token punctuation">:</span>
            docxUrl <span class="token operator">=</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"新文件路径："</span> <span class="token operator">+</span> docxUrl<span class="token punctuation">)</span>

        word <span class="token operator">=</span>win32com<span class="token punctuation">.</span>client<span class="token punctuation">.</span>Dispatch<span class="token punctuation">(</span><span class="token string">'kwps.application'</span><span class="token punctuation">)</span> <span class="token comment">#win32com.client.gencache.EnsureDispatch('kwps.Application')</span>
        word<span class="token punctuation">.</span>DisplayAlerts <span class="token operator">=</span> <span class="token number">0</span>
        word<span class="token punctuation">.</span>Visible <span class="token operator">=</span> <span class="token number">0</span>
        fileTotal <span class="token operator">=</span> <span class="token number">0</span>
        total <span class="token operator">=</span> <span class="token number">0</span>

        <span class="token keyword">for</span> root<span class="token punctuation">,</span> dirs<span class="token punctuation">,</span> files <span class="token keyword">in</span> os<span class="token punctuation">.</span>walk<span class="token punctuation">(</span>docUrl<span class="token punctuation">)</span><span class="token punctuation">:</span>            
            <span class="token keyword">for</span> name <span class="token keyword">in</span> files<span class="token punctuation">:</span>
                length <span class="token operator">=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                index <span class="token operator">=</span> name<span class="token punctuation">.</span>rfind<span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span>
                after <span class="token operator">=</span> name<span class="token punctuation">[</span>index<span class="token punctuation">:</span>length<span class="token punctuation">]</span>
                after <span class="token operator">=</span> after<span class="token punctuation">.</span>lower<span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token keyword">if</span> after <span class="token operator">==</span> <span class="token string">'.doc'</span> <span class="token keyword">or</span> after <span class="token operator">==</span> <span class="token string">'.docx'</span><span class="token punctuation">:</span>                
                    fileTotal <span class="token operator">+=</span> <span class="token number">1</span>
        <span class="token keyword">for</span> root<span class="token punctuation">,</span> dirs<span class="token punctuation">,</span> files <span class="token keyword">in</span> os<span class="token punctuation">.</span>walk<span class="token punctuation">(</span>docUrl<span class="token punctuation">)</span><span class="token punctuation">:</span>
            self<span class="token punctuation">.</span>statusbar<span class="token punctuation">.</span>showMessage<span class="token punctuation">(</span><span class="token string">"正在转换["</span> <span class="token operator">+</span> root <span class="token operator">+</span> <span class="token string">"]中的"</span><span class="token operator">+</span><span class="token builtin">repr</span><span class="token punctuation">(</span>fileTotal<span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"个word文件。"</span><span class="token punctuation">)</span>
            self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token string">"正在转换["</span> <span class="token operator">+</span> root <span class="token operator">+</span> <span class="token string">"]中的"</span><span class="token operator">+</span><span class="token builtin">repr</span><span class="token punctuation">(</span>fileTotal<span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"个word文件。"</span><span class="token punctuation">)</span>
            <span class="token keyword">for</span> name <span class="token keyword">in</span> files<span class="token punctuation">:</span>
                length <span class="token operator">=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                index <span class="token operator">=</span> name<span class="token punctuation">.</span>rfind<span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span>
                after <span class="token operator">=</span> name<span class="token punctuation">[</span>index<span class="token punctuation">:</span>length<span class="token punctuation">]</span>
                after <span class="token operator">=</span> after<span class="token punctuation">.</span>lower<span class="token punctuation">(</span><span class="token punctuation">)</span>
                total <span class="token operator">+=</span> <span class="token number">1</span>
                <span class="token keyword">if</span> after <span class="token operator">==</span> <span class="token string">'.doc'</span> <span class="token keyword">or</span> after <span class="token operator">==</span> <span class="token string">'.docx'</span><span class="token punctuation">:</span>
                    self<span class="token punctuation">.</span>totalList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                    value <span class="token operator">=</span> total <span class="token operator">*</span> <span class="token number">1.0</span> <span class="token operator">/</span> fileTotal <span class="token operator">*</span> <span class="token number">100</span>
                    self<span class="token punctuation">.</span>progressBar<span class="token punctuation">.</span>setValue<span class="token punctuation">(</span><span class="token builtin">int</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">)</span>
                    fileName <span class="token operator">=</span> root <span class="token operator">+</span> <span class="token string">"/"</span> <span class="token operator">+</span> name
                    <span class="token comment">#print(fileName)</span>
                    <span class="token keyword">try</span><span class="token punctuation">:</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span>fileName<span class="token punctuation">)</span>

                        doc <span class="token operator">=</span> word<span class="token punctuation">.</span>Documents<span class="token punctuation">.</span>Open<span class="token punctuation">(</span>fileName<span class="token punctuation">)</span>
                        <span class="token comment"># 这个是保存的目录</span>

                        doc<span class="token punctuation">.</span>SaveAs<span class="token punctuation">(</span>docxUrl <span class="token operator">+</span> <span class="token string">"/"</span> <span class="token operator">+</span> name <span class="token operator">+</span> <span class="token string">"x"</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span>
                        <span class="token comment">#print(docxUrl + "/" + name + "x")</span>
                        doc<span class="token punctuation">.</span>Close<span class="token punctuation">(</span><span class="token punctuation">)</span>
                        <span class="token builtin">str</span> <span class="token operator">=</span> name <span class="token operator">+</span> <span class="token string">"转换成功！"</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>successList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                    <span class="token keyword">except</span> Exception <span class="token keyword">as</span> e<span class="token punctuation">:</span>
                        <span class="token comment">#print(fileName)</span>
                        <span class="token builtin">str</span> <span class="token operator">=</span> name <span class="token operator">+</span> <span class="token string">"转换失败！"</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>errorList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                        <span class="token keyword">continue</span>
        word<span class="token punctuation">.</span>Quit<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token string">"本次操作结束！"</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>setOp<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        <span class="token comment">#self.writeMsg()</span>
    
    <span class="token comment">#转换为PDF</span>
    <span class="token keyword">def</span> <span class="token function">startConvertP</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token keyword">if</span> self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token string">''</span><span class="token punctuation">:</span><span class="token comment"># or self.docxLineEdit.text() == '':</span>
            msgBox <span class="token operator">=</span> QMessageBox<span class="token punctuation">(</span>QMessageBox<span class="token punctuation">.</span>Warning<span class="token punctuation">,</span> <span class="token string">"警告"</span><span class="token punctuation">,</span> <span class="token string">"请选中要转换的目录"</span><span class="token punctuation">)</span>
            msgBox<span class="token punctuation">.</span><span class="token keyword">exec</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span>
        self<span class="token punctuation">.</span>setOp<span class="token punctuation">(</span><span class="token boolean">False</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>initConfig<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token comment">#获取文本同时去掉空格</span>
        docUrl <span class="token operator">=</span> self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"原文件路径："</span> <span class="token operator">+</span> docUrl<span class="token punctuation">)</span>
        <span class="token keyword">if</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token string">''</span><span class="token punctuation">:</span>
            docxUrl<span class="token operator">=</span>docUrl
        <span class="token keyword">else</span><span class="token punctuation">:</span>
            docxUrl <span class="token operator">=</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"新文件路径："</span> <span class="token operator">+</span> docxUrl<span class="token punctuation">)</span>
        word <span class="token operator">=</span>win32com<span class="token punctuation">.</span>client<span class="token punctuation">.</span>Dispatch<span class="token punctuation">(</span><span class="token string">'kwps.application'</span><span class="token punctuation">)</span> <span class="token comment"># win32com.client.gencache.EnsureDispatch('kwps.Application')</span>
        word<span class="token punctuation">.</span>DisplayAlerts <span class="token operator">=</span> <span class="token number">0</span>
        word<span class="token punctuation">.</span>Visible <span class="token operator">=</span> <span class="token number">0</span>
        fileTotal <span class="token operator">=</span> <span class="token number">0</span>
        total <span class="token operator">=</span> <span class="token number">0</span>

        <span class="token keyword">for</span> root<span class="token punctuation">,</span> dirs<span class="token punctuation">,</span> files <span class="token keyword">in</span> os<span class="token punctuation">.</span>walk<span class="token punctuation">(</span>docUrl<span class="token punctuation">)</span><span class="token punctuation">:</span>            
            <span class="token keyword">for</span> name <span class="token keyword">in</span> files<span class="token punctuation">:</span>
                length <span class="token operator">=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                index <span class="token operator">=</span> name<span class="token punctuation">.</span>rfind<span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span>
                after <span class="token operator">=</span> name<span class="token punctuation">[</span>index<span class="token punctuation">:</span>length<span class="token punctuation">]</span>
                after <span class="token operator">=</span> after<span class="token punctuation">.</span>lower<span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token keyword">if</span> after <span class="token operator">==</span> <span class="token string">'.doc'</span> <span class="token keyword">or</span> after <span class="token operator">==</span> <span class="token string">'.docx'</span><span class="token punctuation">:</span>                
                    fileTotal <span class="token operator">+=</span> <span class="token number">1</span>
        <span class="token keyword">for</span> root<span class="token punctuation">,</span> dirs<span class="token punctuation">,</span> files <span class="token keyword">in</span> os<span class="token punctuation">.</span>walk<span class="token punctuation">(</span>docUrl<span class="token punctuation">)</span><span class="token punctuation">:</span>
            self<span class="token punctuation">.</span>statusbar<span class="token punctuation">.</span>showMessage<span class="token punctuation">(</span><span class="token string">"正在转换["</span> <span class="token operator">+</span> root <span class="token operator">+</span> <span class="token string">"]中的"</span><span class="token operator">+</span><span class="token builtin">repr</span><span class="token punctuation">(</span>fileTotal<span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"个word文件。"</span><span class="token punctuation">)</span>
            <span class="token keyword">for</span> name <span class="token keyword">in</span> files<span class="token punctuation">:</span>
                length <span class="token operator">=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                index <span class="token operator">=</span> name<span class="token punctuation">.</span>rfind<span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span>
                after <span class="token operator">=</span> name<span class="token punctuation">[</span>index<span class="token punctuation">:</span>length<span class="token punctuation">]</span>
                after <span class="token operator">=</span> after<span class="token punctuation">.</span>lower<span class="token punctuation">(</span><span class="token punctuation">)</span>
                total <span class="token operator">+=</span> <span class="token number">1</span>
                <span class="token keyword">if</span> after <span class="token operator">==</span> <span class="token string">'.doc'</span> <span class="token keyword">or</span> after <span class="token operator">==</span> <span class="token string">'.docx'</span><span class="token punctuation">:</span>
                    self<span class="token punctuation">.</span>totalList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                    value <span class="token operator">=</span> total <span class="token operator">*</span> <span class="token number">1.0</span> <span class="token operator">/</span> fileTotal <span class="token operator">*</span> <span class="token number">100</span>
                    self<span class="token punctuation">.</span>progressBar<span class="token punctuation">.</span>setValue<span class="token punctuation">(</span><span class="token builtin">int</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">)</span>
                    fileName <span class="token operator">=</span> root <span class="token operator">+</span> <span class="token string">"/"</span> <span class="token operator">+</span> name
                    <span class="token keyword">try</span><span class="token punctuation">:</span>
                        doc <span class="token operator">=</span> word<span class="token punctuation">.</span>Documents<span class="token punctuation">.</span>Open<span class="token punctuation">(</span>fileName<span class="token punctuation">)</span>
                        <span class="token comment"># 这个是保存的目录</span>

                        doc<span class="token punctuation">.</span>SaveAs<span class="token punctuation">(</span>docxUrl <span class="token operator">+</span> <span class="token string">"/"</span> <span class="token operator">+</span>os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>splitext<span class="token punctuation">(</span>name<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">+</span> <span class="token string">".pdf"</span><span class="token punctuation">,</span> <span class="token number">17</span><span class="token punctuation">)</span>
                        doc<span class="token punctuation">.</span>Close<span class="token punctuation">(</span><span class="token punctuation">)</span>
                        <span class="token builtin">str</span> <span class="token operator">=</span> name <span class="token operator">+</span> <span class="token string">"转换成功！"</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>successList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                    <span class="token keyword">except</span> Exception <span class="token keyword">as</span> e<span class="token punctuation">:</span>
                        <span class="token builtin">str</span> <span class="token operator">=</span> name <span class="token operator">+</span> <span class="token string">"转换失败！"</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>errorList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                        <span class="token keyword">continue</span>
        word<span class="token punctuation">.</span>Quit<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token string">"本次操作结束！"</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>setOp<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        <span class="token comment">#self.writeMsg()</span>
    
    <span class="token comment">#删除页眉页脚</span>
    <span class="token keyword">def</span> <span class="token function">remove_H_F</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        replace_dict <span class="token operator">=</span> <span class="token punctuation">&#123;</span>
            <span class="token string">"."</span><span class="token punctuation">:</span> <span class="token string">"．"</span><span class="token punctuation">,</span>
            <span class="token string">"。"</span><span class="token punctuation">:</span> <span class="token string">"．"</span><span class="token punctuation">,</span>
            <span class="token string">","</span><span class="token punctuation">:</span> <span class="token string">"，"</span><span class="token punctuation">,</span>
            <span class="token string">";"</span><span class="token punctuation">:</span> <span class="token string">"；"</span><span class="token punctuation">,</span>
            <span class="token string">":"</span><span class="token punctuation">:</span> <span class="token string">"："</span><span class="token punctuation">,</span>
            <span class="token string">"-"</span><span class="token punctuation">:</span> <span class="token string">"－"</span><span class="token punctuation">,</span>
            <span class="token string">"+"</span><span class="token punctuation">:</span> <span class="token string">"＋"</span><span class="token punctuation">,</span>
            <span class="token string">"^b"</span><span class="token punctuation">:</span> <span class="token string">""</span><span class="token punctuation">,</span>
            <span class="token string">"【分析】^p"</span><span class="token punctuation">:</span><span class="token string">"【分析】"</span><span class="token punctuation">,</span>
            <span class="token string">"【详解】^p"</span><span class="token punctuation">:</span><span class="token string">"【详解】"</span><span class="token punctuation">,</span>
            <span class="token string">"【点睛】^p"</span><span class="token punctuation">:</span><span class="token string">"【点睛】"</span><span class="token punctuation">,</span>
        <span class="token punctuation">&#125;</span>        

        <span class="token keyword">def</span> <span class="token function">check_and_change</span><span class="token punctuation">(</span>document<span class="token punctuation">,</span> replace_dict<span class="token punctuation">)</span><span class="token punctuation">:</span>
            <span class="token triple-quoted-string string">"""
            遍历word中的所有 paragraphs，在每一段中发现含有key 的内容，就替换为 value 。 
            （key 和 value 都是replace_dict中的键值对。）
            """</span>
            <span class="token keyword">for</span> para <span class="token keyword">in</span> document<span class="token punctuation">.</span>paragraphs<span class="token punctuation">:</span>
                <span class="token keyword">for</span> i <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>para<span class="token punctuation">.</span>runs<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
                    <span class="token keyword">for</span> key<span class="token punctuation">,</span> value <span class="token keyword">in</span> replace_dict<span class="token punctuation">.</span>items<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
                        <span class="token keyword">if</span> key <span class="token keyword">in</span> para<span class="token punctuation">.</span>runs<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">.</span>text<span class="token punctuation">:</span>
                            para<span class="token punctuation">.</span>runs<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">.</span>text <span class="token operator">=</span> para<span class="token punctuation">.</span>runs<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">.</span>text<span class="token punctuation">.</span>replace<span class="token punctuation">(</span>key<span class="token punctuation">,</span> value<span class="token punctuation">)</span>
            <span class="token keyword">return</span> document

        <span class="token keyword">if</span> self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token string">''</span><span class="token punctuation">:</span><span class="token comment"># or self.docxLineEdit.text() == '':</span>
            msgBox <span class="token operator">=</span> QMessageBox<span class="token punctuation">(</span>QMessageBox<span class="token punctuation">.</span>Warning<span class="token punctuation">,</span> <span class="token string">"警告"</span><span class="token punctuation">,</span> <span class="token string">"请选中要操作的目录"</span><span class="token punctuation">)</span>
            msgBox<span class="token punctuation">.</span><span class="token keyword">exec</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span>
        self<span class="token punctuation">.</span>setOp<span class="token punctuation">(</span><span class="token boolean">False</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>initConfig<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token comment">#获取文本同时去掉空格</span>
        docUrl <span class="token operator">=</span> self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"原文件路径："</span> <span class="token operator">+</span> docUrl<span class="token punctuation">)</span>
        <span class="token keyword">if</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token string">''</span><span class="token punctuation">:</span>
            docxUrl<span class="token operator">=</span>docUrl
        <span class="token keyword">else</span><span class="token punctuation">:</span>
            docxUrl <span class="token operator">=</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"新文件路径："</span> <span class="token operator">+</span> docxUrl<span class="token punctuation">)</span>
        word <span class="token operator">=</span>win32com<span class="token punctuation">.</span>client<span class="token punctuation">.</span>DispatchEx<span class="token punctuation">(</span><span class="token string">'word.application'</span><span class="token punctuation">)</span> <span class="token comment">#win32com.client.gencache.EnsureDispatch('kwps.Application')</span>
        word<span class="token punctuation">.</span>DisplayAlerts <span class="token operator">=</span> <span class="token number">0</span>
        word<span class="token punctuation">.</span>Visible <span class="token operator">=</span> <span class="token number">0</span>
        fileTotal <span class="token operator">=</span> <span class="token number">0</span>
        total <span class="token operator">=</span> <span class="token number">0</span>

        <span class="token keyword">for</span> root<span class="token punctuation">,</span> dirs<span class="token punctuation">,</span> files <span class="token keyword">in</span> os<span class="token punctuation">.</span>walk<span class="token punctuation">(</span>docUrl<span class="token punctuation">)</span><span class="token punctuation">:</span>            
            <span class="token keyword">for</span> name <span class="token keyword">in</span> files<span class="token punctuation">:</span>
                length <span class="token operator">=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                index <span class="token operator">=</span> name<span class="token punctuation">.</span>rfind<span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span>
                after <span class="token operator">=</span> name<span class="token punctuation">[</span>index<span class="token punctuation">:</span>length<span class="token punctuation">]</span>
                after <span class="token operator">=</span> after<span class="token punctuation">.</span>lower<span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token keyword">if</span> after <span class="token operator">==</span> <span class="token string">'.doc'</span> <span class="token keyword">or</span> after <span class="token operator">==</span> <span class="token string">'.docx'</span><span class="token punctuation">:</span>                
                    fileTotal <span class="token operator">+=</span> <span class="token number">1</span>
        <span class="token keyword">for</span> root<span class="token punctuation">,</span> dirs<span class="token punctuation">,</span> files <span class="token keyword">in</span> os<span class="token punctuation">.</span>walk<span class="token punctuation">(</span>docUrl<span class="token punctuation">)</span><span class="token punctuation">:</span>
            self<span class="token punctuation">.</span>statusbar<span class="token punctuation">.</span>showMessage<span class="token punctuation">(</span><span class="token string">"正在操作["</span> <span class="token operator">+</span> root <span class="token operator">+</span> <span class="token string">"]中的"</span><span class="token operator">+</span><span class="token builtin">repr</span><span class="token punctuation">(</span>fileTotal<span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"个word文件。"</span><span class="token punctuation">)</span>
            <span class="token keyword">for</span> name <span class="token keyword">in</span> files<span class="token punctuation">:</span>
                length <span class="token operator">=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                index <span class="token operator">=</span> name<span class="token punctuation">.</span>rfind<span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span>
                after <span class="token operator">=</span> name<span class="token punctuation">[</span>index<span class="token punctuation">:</span>length<span class="token punctuation">]</span>
                after <span class="token operator">=</span> after<span class="token punctuation">.</span>lower<span class="token punctuation">(</span><span class="token punctuation">)</span>
                total <span class="token operator">+=</span> <span class="token number">1</span>
                <span class="token keyword">if</span> after <span class="token operator">==</span> <span class="token string">'.doc'</span> <span class="token keyword">or</span> after <span class="token operator">==</span> <span class="token string">'.docx'</span><span class="token punctuation">:</span>
                    self<span class="token punctuation">.</span>totalList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                    value <span class="token operator">=</span> total <span class="token operator">*</span> <span class="token number">1.0</span> <span class="token operator">/</span> fileTotal <span class="token operator">*</span> <span class="token number">100</span>
                    self<span class="token punctuation">.</span>progressBar<span class="token punctuation">.</span>setValue<span class="token punctuation">(</span><span class="token builtin">int</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">)</span>
                    fileName <span class="token operator">=</span> root <span class="token operator">+</span> <span class="token string">"/"</span> <span class="token operator">+</span> name
                    <span class="token keyword">print</span><span class="token punctuation">(</span>fileName<span class="token punctuation">,</span>total<span class="token punctuation">)</span>
                    <span class="token keyword">try</span><span class="token punctuation">:</span>
                        <span class="token comment">#print("1:"+fileName)</span>
                        <span class="token comment">#print("2:"+name)</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                        <span class="token comment">#doc = word.Documents.Open(fileName)</span>
                        <span class="token comment"># 这个是保存的目录</span>

                        <span class="token builtin">file</span><span class="token operator">=</span>docx<span class="token punctuation">.</span>Document<span class="token punctuation">(</span>fileName<span class="token punctuation">)</span>
                        <span class="token comment">#取消"首页不同"，对每一节分别设置</span>
                        <span class="token comment">#file.sections[0].different_first_page_header_footer = False </span>
                        <span class="token comment"># 取消"奇偶页不同"，对整个文档有效</span>
                        <span class="token comment">#file.settings.odd_and_even_pages_header_footer=False</span>
                        sstr<span class="token operator">=</span><span class="token string">"本文档共有"</span><span class="token operator">+</span><span class="token builtin">repr</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"节。"</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span>sstr<span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span>sstr<span class="token punctuation">)</span>

                        a<span class="token operator">=</span><span class="token number">0</span>
                        <span class="token keyword">while</span> a <span class="token operator">&lt;</span> <span class="token builtin">len</span><span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token comment">#文档有多节时，要分别设置，以下是统一设置成一样格式</span>
                            <span class="token comment"># 删除页眉、页脚            </span>
                            <span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">.</span>header<span class="token punctuation">.</span>is_linked_to_previous<span class="token operator">=</span><span class="token boolean">True</span>
                            <span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">.</span>footer<span class="token punctuation">.</span>is_linked_to_previous<span class="token operator">=</span><span class="token boolean">True</span>

                            <span class="token comment">#file.sections[a].header.paragraphs[0].text= ''#你要修改成的页眉'</span>
                            <span class="token comment">#file.sections[a].footer.paragraphs[0].text= ''#你要修改成的页脚'</span>
       
                            <span class="token comment">#修改页边距</span>
                            <span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">.</span>mirrorMargins <span class="token operator">=</span><span class="token boolean">True</span>
                            <span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">.</span>top_margin <span class="token operator">=</span> Cm<span class="token punctuation">(</span><span class="token number">1.8</span><span class="token punctuation">)</span>
                            <span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">.</span>bottom_margin <span class="token operator">=</span> Cm<span class="token punctuation">(</span><span class="token number">1.8</span><span class="token punctuation">)</span>
                            <span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">.</span>left_margin <span class="token operator">=</span> Cm<span class="token punctuation">(</span><span class="token number">1.8</span><span class="token punctuation">)</span>
                            <span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">.</span>right_margin <span class="token operator">=</span> Cm<span class="token punctuation">(</span><span class="token number">1.8</span><span class="token punctuation">)</span>
            
                            <span class="token comment">#修改页眉页脚离页面边距</span>
                            <span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">.</span>header_distance <span class="token operator">=</span> Cm<span class="token punctuation">(</span><span class="token number">1.2</span><span class="token punctuation">)</span>
                            <span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">.</span>footer_distance <span class="token operator">=</span> Cm<span class="token punctuation">(</span><span class="token number">1.2</span><span class="token punctuation">)</span>

                            <span class="token triple-quoted-string string">'''
                            #设置纸张方向和大小
                            file.sections[0].page_height = Cm(29.7)  # 设置A4纸的高度
                            file.sections[0].page_width = Cm(21)  # 设置A4纸的宽
                            file.sections[0].orientation = WD_ORIENTATION.PORTRAIT # 设置纸张方向为横向，可以不设置 默认为横向
                            file.sections[1].orientation = WD_ORIENTATION.LANDSCAPE # 设置纸张方向为纵向
                            file.sections[1].page_height = Cm(21)  # 设置A4纸的高度
                            file.sections[1].page_width = Cm(29.7)  # 设置A4纸的宽

                            #设置分栏
                            file.sections[0]._sectPr.xpath('./w:cols')[0].set(qn('w:num'), '2') #把第一节设置为2栏
    
                            #设置段落间距
                            paragraph_format=file.paragraphs[0].paragraph_format
                            paragraph_format.space_before=Pt(18)    #段前间距
                            paragraph_format.space_after=Pt(12)    #段后间距
                            paragraph_format.line_spacing=Pt(12)  #行距
                            '''</span>
                            <span class="token keyword">for</span>  paragraph  <span class="token keyword">in</span>  <span class="token builtin">file</span><span class="token punctuation">.</span>paragraphs<span class="token punctuation">:</span>
                                <span class="token keyword">if</span>  paragraph<span class="token punctuation">.</span>style<span class="token punctuation">.</span>name<span class="token operator">==</span><span class="token string">'Normal'</span><span class="token punctuation">:</span>
                                    paragraph<span class="token punctuation">.</span>paragraph_format<span class="token punctuation">.</span>line_spacing<span class="token operator">=</span><span class="token number">1.0</span><span class="token comment">#设置为单倍行距</span>

                            check_and_change<span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">,</span> replace_dict<span class="token punctuation">)</span><span class="token comment">#替换字符</span>
                            <span class="token builtin">file</span><span class="token punctuation">.</span>save<span class="token punctuation">(</span>os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>docxUrl<span class="token punctuation">,</span>name<span class="token punctuation">)</span><span class="token punctuation">)</span>
                            a<span class="token operator">+=</span><span class="token number">1</span>
                        <span class="token builtin">str</span> <span class="token operator">=</span> name <span class="token operator">+</span> <span class="token string">"删除页眉页脚成功！"</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>successList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>                        
                    <span class="token keyword">except</span> Exception <span class="token keyword">as</span> e<span class="token punctuation">:</span>
                        self<span class="token punctuation">.</span>errorList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span>
                        <span class="token builtin">str</span> <span class="token operator">=</span> name <span class="token operator">+</span> <span class="token string">"删除页眉页脚失败！"</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>errorList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>

                <span class="token keyword">continue</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"操作完成！"</span><span class="token punctuation">)</span>
            self<span class="token punctuation">.</span>statusbar<span class="token punctuation">.</span>showMessage<span class="token punctuation">(</span><span class="token string">"操作完成!"</span><span class="token punctuation">)</span>

        word<span class="token punctuation">.</span>Quit<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token string">"本次操作结束！"</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>setOp<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        <span class="token comment">#self.writeMsg()</span>

    <span class="token comment">#添加页码</span>
    <span class="token keyword">def</span> <span class="token function">addPageNumber</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>

        <span class="token keyword">if</span> self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token string">''</span><span class="token punctuation">:</span><span class="token comment"># or self.docxLineEdit.text() == '':</span>
            msgBox <span class="token operator">=</span> QMessageBox<span class="token punctuation">(</span>QMessageBox<span class="token punctuation">.</span>Warning<span class="token punctuation">,</span> <span class="token string">"警告"</span><span class="token punctuation">,</span> <span class="token string">"请选中要转换的目录"</span><span class="token punctuation">)</span>
            msgBox<span class="token punctuation">.</span><span class="token keyword">exec</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span>
        self<span class="token punctuation">.</span>setOp<span class="token punctuation">(</span><span class="token boolean">False</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>initConfig<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token comment">#获取文本同时去掉空格</span>
        docUrl <span class="token operator">=</span> self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"原文件路径："</span> <span class="token operator">+</span> docUrl<span class="token punctuation">)</span>
        <span class="token keyword">if</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token string">''</span><span class="token punctuation">:</span>
            docxUrl<span class="token operator">=</span>docUrl
        <span class="token keyword">else</span><span class="token punctuation">:</span>
            docxUrl <span class="token operator">=</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"新文件路径："</span> <span class="token operator">+</span> docxUrl<span class="token punctuation">)</span>
        word <span class="token operator">=</span> win32com<span class="token punctuation">.</span>client<span class="token punctuation">.</span>DispatchEx<span class="token punctuation">(</span><span class="token string">'kwps.application'</span><span class="token punctuation">)</span> <span class="token comment"># win32com.client.gencache.EnsureDispatch('kwps.Application')</span>
        word<span class="token punctuation">.</span>DisplayAlerts <span class="token operator">=</span> <span class="token number">0</span>
        word<span class="token punctuation">.</span>Visible <span class="token operator">=</span> <span class="token number">0</span>
        fileTotal <span class="token operator">=</span> <span class="token number">0</span>
        total <span class="token operator">=</span> <span class="token number">0</span>

        <span class="token keyword">for</span> root<span class="token punctuation">,</span> dirs<span class="token punctuation">,</span> files <span class="token keyword">in</span> os<span class="token punctuation">.</span>walk<span class="token punctuation">(</span>docUrl<span class="token punctuation">)</span><span class="token punctuation">:</span>            
            <span class="token keyword">for</span> name <span class="token keyword">in</span> files<span class="token punctuation">:</span>
                length <span class="token operator">=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                index <span class="token operator">=</span> name<span class="token punctuation">.</span>rfind<span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span>
                after <span class="token operator">=</span> name<span class="token punctuation">[</span>index<span class="token punctuation">:</span>length<span class="token punctuation">]</span>
                after <span class="token operator">=</span> after<span class="token punctuation">.</span>lower<span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token keyword">if</span> after <span class="token operator">==</span> <span class="token string">'.doc'</span> <span class="token keyword">or</span> after <span class="token operator">==</span> <span class="token string">'.docx'</span><span class="token punctuation">:</span>                
                    fileTotal <span class="token operator">+=</span> <span class="token number">1</span>
        <span class="token keyword">for</span> root<span class="token punctuation">,</span> dirs<span class="token punctuation">,</span> files <span class="token keyword">in</span> os<span class="token punctuation">.</span>walk<span class="token punctuation">(</span>docUrl<span class="token punctuation">)</span><span class="token punctuation">:</span>
            self<span class="token punctuation">.</span>statusbar<span class="token punctuation">.</span>showMessage<span class="token punctuation">(</span><span class="token string">"正在操作["</span> <span class="token operator">+</span> root <span class="token operator">+</span> <span class="token string">"]中的"</span><span class="token operator">+</span><span class="token builtin">repr</span><span class="token punctuation">(</span>fileTotal<span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"个word文件。"</span><span class="token punctuation">)</span>
            <span class="token keyword">for</span> name <span class="token keyword">in</span> files<span class="token punctuation">:</span>
                length <span class="token operator">=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                index <span class="token operator">=</span> name<span class="token punctuation">.</span>rfind<span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span>
                after <span class="token operator">=</span> name<span class="token punctuation">[</span>index<span class="token punctuation">:</span>length<span class="token punctuation">]</span>
                after <span class="token operator">=</span> after<span class="token punctuation">.</span>lower<span class="token punctuation">(</span><span class="token punctuation">)</span>
                total <span class="token operator">+=</span> <span class="token number">1</span>
                <span class="token keyword">if</span> after <span class="token operator">==</span> <span class="token string">'.doc'</span> <span class="token keyword">or</span> after <span class="token operator">==</span> <span class="token string">'.docx'</span><span class="token punctuation">:</span>
                    self<span class="token punctuation">.</span>totalList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                    value <span class="token operator">=</span> total <span class="token operator">*</span> <span class="token number">1.0</span> <span class="token operator">/</span> fileTotal <span class="token operator">*</span> <span class="token number">100</span>
                    self<span class="token punctuation">.</span>progressBar<span class="token punctuation">.</span>setValue<span class="token punctuation">(</span><span class="token builtin">int</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">)</span>
                    fileName <span class="token operator">=</span> root <span class="token operator">+</span> <span class="token string">"/"</span> <span class="token operator">+</span> name
                    newName <span class="token operator">=</span> docxUrl <span class="token operator">+</span> <span class="token string">"/"</span> <span class="token operator">+</span> name
                    <span class="token comment">#print(newName,total)</span>
                    <span class="token keyword">try</span><span class="token punctuation">:</span>
                        doc <span class="token operator">=</span> word<span class="token punctuation">.</span>Documents<span class="token punctuation">.</span>Open<span class="token punctuation">(</span>fileName<span class="token punctuation">)</span>
                        
                        wd_section <span class="token operator">=</span> doc<span class="token punctuation">.</span>Sections<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment">#注意section内部成员编号是从1开始的</span>
                        wd_section<span class="token punctuation">.</span>Footers<span class="token punctuation">(</span>constants<span class="token punctuation">.</span>wdHeaderFooterPrimary<span class="token punctuation">)</span><span class="token punctuation">.</span>PageNumbers<span class="token punctuation">.</span>Add<span class="token punctuation">(</span>PageNumberAlignment<span class="token operator">=</span>constants<span class="token punctuation">.</span>wdAlignPageNumberCenter<span class="token punctuation">)</span> <span class="token comment">#添加页码</span>
                
                        doc<span class="token punctuation">.</span>SaveAs<span class="token punctuation">(</span>newName<span class="token punctuation">)</span>                        
                        doc<span class="token punctuation">.</span>Close<span class="token punctuation">(</span><span class="token punctuation">)</span>

                        <span class="token builtin">str</span> <span class="token operator">=</span> name <span class="token operator">+</span> <span class="token string">"添加页码成功！"</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>successList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>                        
                    <span class="token keyword">except</span> Exception <span class="token keyword">as</span> e<span class="token punctuation">:</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span>
                        <span class="token builtin">str</span> <span class="token operator">=</span> name <span class="token operator">+</span> <span class="token string">"添加页码失败！"</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>errorList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>

                <span class="token keyword">continue</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"操作完成！"</span><span class="token punctuation">)</span>
            self<span class="token punctuation">.</span>statusbar<span class="token punctuation">.</span>showMessage<span class="token punctuation">(</span><span class="token string">"操作完成!"</span><span class="token punctuation">)</span>

        word<span class="token punctuation">.</span>Quit<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token string">"本次操作结束！"</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>setOp<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        <span class="token comment">#self.writeMsg()#添加页码</span>

    <span class="token comment">#删除页眉</span>
    <span class="token keyword">def</span> <span class="token function">remove_H</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token keyword">if</span> self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token string">''</span><span class="token punctuation">:</span><span class="token comment"># or self.docxLineEdit.text() == '':</span>
            msgBox <span class="token operator">=</span> QMessageBox<span class="token punctuation">(</span>QMessageBox<span class="token punctuation">.</span>Warning<span class="token punctuation">,</span> <span class="token string">"警告"</span><span class="token punctuation">,</span> <span class="token string">"请选中要操作的目录！"</span><span class="token punctuation">)</span>
            msgBox<span class="token punctuation">.</span><span class="token keyword">exec</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token keyword">return</span>
        self<span class="token punctuation">.</span>setOp<span class="token punctuation">(</span><span class="token boolean">False</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>initConfig<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token comment">#获取文本同时去掉空格</span>
        docUrl <span class="token operator">=</span> self<span class="token punctuation">.</span>docLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"原文件路径："</span> <span class="token operator">+</span> docUrl<span class="token punctuation">)</span>
        <span class="token keyword">if</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token string">''</span><span class="token punctuation">:</span>
            docxUrl<span class="token operator">=</span>docUrl
        <span class="token keyword">else</span><span class="token punctuation">:</span>
            docxUrl <span class="token operator">=</span> self<span class="token punctuation">.</span>docxLineEdit<span class="token punctuation">.</span>text<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"新文件路径："</span> <span class="token operator">+</span> docxUrl<span class="token punctuation">)</span>
        word <span class="token operator">=</span> win32com<span class="token punctuation">.</span>client<span class="token punctuation">.</span>DispatchEx<span class="token punctuation">(</span><span class="token string">'kwps.application'</span><span class="token punctuation">)</span> <span class="token comment"># win32com.client.gencache.EnsureDispatch('kwps.Application')</span>
        word<span class="token punctuation">.</span>DisplayAlerts <span class="token operator">=</span> <span class="token number">0</span>
        word<span class="token punctuation">.</span>Visible <span class="token operator">=</span> <span class="token number">0</span>
        fileTotal <span class="token operator">=</span> <span class="token number">0</span>
        total <span class="token operator">=</span> <span class="token number">0</span>

        <span class="token keyword">for</span> root<span class="token punctuation">,</span> dirs<span class="token punctuation">,</span> files <span class="token keyword">in</span> os<span class="token punctuation">.</span>walk<span class="token punctuation">(</span>docUrl<span class="token punctuation">)</span><span class="token punctuation">:</span>            
            <span class="token keyword">for</span> name <span class="token keyword">in</span> files<span class="token punctuation">:</span>
                length <span class="token operator">=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                index <span class="token operator">=</span> name<span class="token punctuation">.</span>rfind<span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span>
                after <span class="token operator">=</span> name<span class="token punctuation">[</span>index<span class="token punctuation">:</span>length<span class="token punctuation">]</span>
                after <span class="token operator">=</span> after<span class="token punctuation">.</span>lower<span class="token punctuation">(</span><span class="token punctuation">)</span>
                <span class="token keyword">if</span> after <span class="token operator">==</span> <span class="token string">'.doc'</span> <span class="token keyword">or</span> after <span class="token operator">==</span> <span class="token string">'.docx'</span><span class="token punctuation">:</span>                
                    fileTotal <span class="token operator">+=</span> <span class="token number">1</span>
        <span class="token keyword">for</span> root<span class="token punctuation">,</span> dirs<span class="token punctuation">,</span> files <span class="token keyword">in</span> os<span class="token punctuation">.</span>walk<span class="token punctuation">(</span>docUrl<span class="token punctuation">)</span><span class="token punctuation">:</span>
            self<span class="token punctuation">.</span>statusbar<span class="token punctuation">.</span>showMessage<span class="token punctuation">(</span><span class="token string">"正在操作["</span> <span class="token operator">+</span> root <span class="token operator">+</span> <span class="token string">"]中的"</span><span class="token operator">+</span><span class="token builtin">repr</span><span class="token punctuation">(</span>fileTotal<span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"个word文件。"</span><span class="token punctuation">)</span>
            <span class="token keyword">for</span> name <span class="token keyword">in</span> files<span class="token punctuation">:</span>
                length <span class="token operator">=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                index <span class="token operator">=</span> name<span class="token punctuation">.</span>rfind<span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span>
                after <span class="token operator">=</span> name<span class="token punctuation">[</span>index<span class="token punctuation">:</span>length<span class="token punctuation">]</span>
                after <span class="token operator">=</span> after<span class="token punctuation">.</span>lower<span class="token punctuation">(</span><span class="token punctuation">)</span>
                total <span class="token operator">+=</span> <span class="token number">1</span>
                <span class="token keyword">if</span> after <span class="token operator">==</span> <span class="token string">'.doc'</span> <span class="token keyword">or</span> after <span class="token operator">==</span> <span class="token string">'.docx'</span><span class="token punctuation">:</span>
                    self<span class="token punctuation">.</span>totalList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                    value <span class="token operator">=</span> total <span class="token operator">*</span> <span class="token number">1.0</span> <span class="token operator">/</span> fileTotal <span class="token operator">*</span> <span class="token number">100</span>
                    self<span class="token punctuation">.</span>progressBar<span class="token punctuation">.</span>setValue<span class="token punctuation">(</span><span class="token builtin">int</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">)</span>
                    fileName <span class="token operator">=</span> root <span class="token operator">+</span> <span class="token string">"/"</span> <span class="token operator">+</span> name
                    <span class="token keyword">print</span><span class="token punctuation">(</span>fileName<span class="token punctuation">,</span>total<span class="token punctuation">)</span>
                    <span class="token keyword">try</span><span class="token punctuation">:</span>
                        <span class="token comment">#print("1:"+fileName)</span>
                        <span class="token comment">#print("2:"+name)</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                        <span class="token comment">#doc = word.Documents.Open(fileName)</span>
                        <span class="token comment"># 这个是保存的目录</span>

                        <span class="token builtin">file</span><span class="token operator">=</span>docx<span class="token punctuation">.</span>Document<span class="token punctuation">(</span>fileName<span class="token punctuation">)</span>
                        <span class="token comment">#取消"首页不同"，对每一节分别设置</span>
                        <span class="token comment">#file.sections[0].different_first_page_header_footer = False </span>
                        <span class="token comment"># 取消"奇偶页不同"，对整个文档有效</span>
                        <span class="token comment">#file.settings.odd_and_even_pages_header_footer=False</span>
                        sstr<span class="token operator">=</span><span class="token string">"本文档共有"</span><span class="token operator">+</span><span class="token builtin">repr</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"节。"</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span>sstr<span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span>sstr<span class="token punctuation">)</span>

                        a<span class="token operator">=</span><span class="token number">0</span>
                        <span class="token keyword">while</span> a <span class="token operator">&lt;</span> <span class="token builtin">len</span><span class="token punctuation">(</span><span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token comment">#文档有多节时，要分别设置，以下是统一设置成一样格式</span>
                            <span class="token comment"># 删除页眉            </span>
                            <span class="token builtin">file</span><span class="token punctuation">.</span>sections<span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">.</span>header<span class="token punctuation">.</span>is_linked_to_previous<span class="token operator">=</span><span class="token boolean">True</span>

                            <span class="token builtin">file</span><span class="token punctuation">.</span>save<span class="token punctuation">(</span>os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>docxUrl<span class="token punctuation">,</span>name<span class="token punctuation">)</span><span class="token punctuation">)</span>
                            a<span class="token operator">+=</span><span class="token number">1</span>
                        <span class="token builtin">str</span> <span class="token operator">=</span> name <span class="token operator">+</span> <span class="token string">"删除页眉成功！"</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>successList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>                        
                    <span class="token keyword">except</span> Exception <span class="token keyword">as</span> e<span class="token punctuation">:</span>
                        self<span class="token punctuation">.</span>errorList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span>
                        <span class="token builtin">str</span> <span class="token operator">=</span> name <span class="token operator">+</span> <span class="token string">"删除页眉失败！"</span>
                        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">)</span>
                        self<span class="token punctuation">.</span>errorList<span class="token punctuation">.</span>append<span class="token punctuation">(</span>name<span class="token punctuation">)</span>

                <span class="token keyword">continue</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"操作完成！"</span><span class="token punctuation">)</span>
            self<span class="token punctuation">.</span>statusbar<span class="token punctuation">.</span>showMessage<span class="token punctuation">(</span><span class="token string">"操作完成!"</span><span class="token punctuation">)</span>

        word<span class="token punctuation">.</span>Quit<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>textEdit<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token string">"本次操作结束！"</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>setOp<span class="token punctuation">(</span><span class="token boolean">True</span><span class="token punctuation">)</span>
        <span class="token comment">#self.writeMsg()</span>
    
    <span class="token keyword">def</span> <span class="token function">showAbout</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        msgBox <span class="token operator">=</span> QMessageBox<span class="token punctuation">(</span>QMessageBox<span class="token punctuation">.</span>Question<span class="token punctuation">,</span> <span class="token string">"关于程序"</span><span class="token punctuation">,</span> <span class="token string">"　　请选择源文件夹和新文件夹（可不选则默认与源文件夹相同）。按顺序点击所需操作按钮，处理完成后在新文件夹下有（操作信息.xlsx），记录了操作的文件总数，操作成功的文件数，操作失败的文件数等详细信息。"</span><span class="token punctuation">)</span>
        msgBox<span class="token punctuation">.</span><span class="token keyword">exec</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token keyword">def</span> <span class="token function">contactAuthor</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        msgBox <span class="token operator">=</span> QMessageBox<span class="token punctuation">(</span>QMessageBox<span class="token punctuation">.</span>Information<span class="token punctuation">,</span> <span class="token string">"联系作者"</span><span class="token punctuation">,</span> <span class="token string">"如您发现BUG及有更好的意见或建议，请联系作者:ZJZ(15263796588)"</span><span class="token punctuation">)</span>
        msgBox<span class="token punctuation">.</span><span class="token keyword">exec</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">"__main__"</span><span class="token punctuation">:</span>
    app <span class="token operator">=</span> QApplication<span class="token punctuation">(</span>sys<span class="token punctuation">.</span>argv<span class="token punctuation">)</span>
    main <span class="token operator">=</span> SimpleDialogForm<span class="token punctuation">(</span><span class="token punctuation">)</span>
    main<span class="token punctuation">.</span>show<span class="token punctuation">(</span><span class="token punctuation">)</span>
    sys<span class="token punctuation">.</span>exit<span class="token punctuation">(</span>app<span class="token punctuation">.</span>exec_<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/programming/about" rel="external nofollow noreferrer">ZJZ</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://zjzsoft.gitee.io/programming/programming/2024/01/19/Python%E6%89%B9%E9%87%8F%E5%A4%84%E7%90%86Word%E6%96%87%E4%BB%B6/">https://zjzsoft.gitee.io/programming/programming/2024/01/19/Python%E6%89%B9%E9%87%8F%E5%A4%84%E7%90%86Word%E6%96%87%E4%BB%B6/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/programming/about" target="_blank">ZJZ</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/programming/tags/word/">
                                    <span class="chip bg-color">word</span>
                                </a>
                            
                                <a href="/programming/tags/python/">
                                    <span class="chip bg-color">python</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/programming/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/programming/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的支持是我前进的动力！</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/programming/medias/reward/alipay.png" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/programming/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/programming/2024/01/20/%E3%80%8A%E5%A2%9E%E5%B9%BF%E8%B4%A4%E6%96%87%EF%BC%88%E4%B8%8A%EF%BC%89%E3%80%8B%E9%87%8A%E4%B9%89/">
                    <div class="card-image">
                        
                        
                        <img src="/programming/medias/featureimages/23.jpg" class="responsive-img" alt="《增广贤文（上）》释义">
                        
                        <span class="card-title">《增广贤文（上）》释义</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2024-01-20
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/programming/categories/%E7%BB%8F%E5%85%B8%E6%96%87%E5%AD%A6/" class="post-category">
                                    经典文学
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/programming/tags/%E6%96%87%E5%AD%A6/">
                        <span class="chip bg-color">文学</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/programming/2024/01/19/%E7%94%9F%E6%B4%BB%E7%9A%84%E6%99%BA%E6%85%A7/">
                    <div class="card-image">
                        
                        
                        <img src="/programming/medias/featureimages/19.jpg" class="responsive-img" alt="生活的智慧">
                        
                        <span class="card-title">生活的智慧</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2024-01-19
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/programming/categories/%E6%97%A5%E5%B8%B8%E7%94%9F%E6%B4%BB/" class="post-category">
                                    日常生活
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/programming/tags/%E9%97%B2%E8%B0%88/">
                        <span class="chip bg-color">闲谈</span>
                    </a>
                    
                    <a href="/programming/tags/%E5%B8%B8%E8%AF%86/">
                        <span class="chip bg-color">常识</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/programming/libs/codeBlock/codeBlockFuction.js"></script>


  <!-- 是否加载使用自带的 prismjs. -->
  <script type="text/javascript" src="/programming/libs/prism/prism.min.js"></script>


<!-- 代码语言 -->

<script type="text/javascript" src="/programming/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/programming/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/programming/libs/codeBlock/codeShrink.js"></script>



    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/programming/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/programming/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="503838841"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/programming/libs/aplayer/APlayer.min.js"></script>
<script src="/programming/libs/aplayer/Meting.min.js"></script>

    

    <div class="container row center-align"
         style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2019-2024</span>
            
            <a href="/programming/about" target="_blank">ZJZ</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            
            <br>
            
            
            
                
            
            
                <span id="busuanzi_container_site_pv">
                &nbsp;|&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;
                    <span id="busuanzi_value_site_pv" class="white-color"></span>
            </span>
            
            
                <span id="busuanzi_container_site_uv">
                &nbsp;|&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;
                    <span id="busuanzi_value_site_uv" class="white-color"></span>
            </span>
            
            <br>

            <!-- 运行天数提醒. -->
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/zjzsoft" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:291473238@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=291473238" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 291473238" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/programming/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 白天和黑夜主题 -->
<div class="stars-con">
    <div id="stars"></div>
    <div id="stars2"></div>
    <div id="stars3"></div>  
</div>

<script>
    function switchNightMode() {
        $('<div class="Cuteen_DarkSky"><div class="Cuteen_DarkPlanet"></div></div>').appendTo($('body')),
        setTimeout(function () {
            $('body').hasClass('DarkMode') 
            ? ($('body').removeClass('DarkMode'), localStorage.setItem('isDark', '0'), $('#sum-moon-icon').removeClass("fa-sun").addClass('fa-moon')) 
            : ($('body').addClass('DarkMode'), localStorage.setItem('isDark', '1'), $('#sum-moon-icon').addClass("fa-sun").removeClass('fa-moon')),
            
            setTimeout(function () {
            $('.Cuteen_DarkSky').fadeOut(1e3, function () {
                $(this).remove()
            })
            }, 2e3)
        })
    }
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/programming/libs/materialize/materialize.min.js"></script>
    <script src="/programming/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/programming/libs/aos/aos.js"></script>
    <script src="/programming/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/programming/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/programming/js/matery.js"></script>

    

    
    
    

    <!-- 雪花特效 -->
    

    <!-- 鼠标星星特效 -->
    

     
        <script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
        <script src="/programming/libs/others/TencentCaptcha.js"></script>
        <button id="TencentCaptcha" data-appid="xxxxxxxxxx" data-cbfn="callback" type="button" hidden></button>
    

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/programming/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/programming/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    <!--腾讯兔小巢-->
    
    

    

    

    
    <script src="/programming/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
